<template>
  <el-tooltip effect="dark" content="全屏" placement="bottom">
    <div class="screen-btn" :class="`fonticon-${isFullscreen ? 'exit' : 'full'}-screen`" @click="click()"></div>
  </el-tooltip>
</template>

<script>
import screenfull from 'screenfull';

export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({ message: '你的浏览器不支持全屏', type: 'warning' });
        return false;
      }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change);
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change);
      }
    }
  }
};
</script>

<style scoped>
.screen-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 18px;
  &:hover {
    color: #1677ff;
    .tip-name {
      color: #1677ff !important;
      a {
        color: #1677ff !important;
      }
    }
  }
}
</style>
